package com.ycfmedical.bed.ui.fragment;

import com.ycfmedical.bed.ApiConfigs;
import com.ycfmedical.bed.Constants;
import com.ycfmedical.bed.adapter.HealthFoodAdapter;
import com.ycfmedical.bed.adapter.HealthRegimenAdapter;
import com.ycfmedical.bed.base.BaseHealthFragment;
import com.ycfmedical.bed.model.HealthResults;
import com.ycfmedical.bed.ui.HealthDetailActivity;

import android.os.Bundle;

import cn.droidlover.xdroidmvp.base.SimpleRecAdapter;
import cn.droidlover.xrecyclerview.RecyclerItemCallback;
import cn.droidlover.xrecyclerview.XRecyclerView;

/**
 * 四季养生 fragment
 * Created by wanglei on 2016/12/31.
 */
public class HealthRegimenFragment extends BaseHealthFragment {

    HealthRegimenAdapter adapter;

    @Override
    public SimpleRecAdapter getAdapter() {
        if (adapter == null) {
            adapter = new HealthRegimenAdapter(context);

            //设置点击事件，点击Item
            adapter.setRecItemClick(new RecyclerItemCallback<HealthResults.ResultBean, HealthRegimenAdapter.ViewHolder>() {
                @Override
                public void onItemClick(int position, HealthResults.ResultBean model, int tag, HealthRegimenAdapter.ViewHolder holder) {
                    super.onItemClick(position, model, tag, holder);
                    switch (tag) {
                        case HealthFoodAdapter.TAG_VIEW:
                            Bundle mBundle = new Bundle();
                            mBundle.putParcelable(Constants.HEALTHNEWS,model);
                            HealthDetailActivity.launch(context,mBundle);
                            break;
                    }
                }
            });
        }
        return adapter;
    }

    @Override
    public void setLayoutManager(XRecyclerView recyclerView) {
        recyclerView.verticalLayoutManager(context);
    }

    // 获得Fragemnt的种类
    @Override
    public int getType() {
        return ApiConfigs.REGIMEN;
    }

    public static HealthRegimenFragment newInstance() {
        return new HealthRegimenFragment();
    }
}
